package acm.pta7;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class 小字辈 {
    public static void main(String[] args) {
        Reader sc=new Reader();
        int n = sc.nextInt();
//        int[] map=new int[100000+1];
        int[] parent=new int[n+1];
        for (int i = 1; i <= n; i++) {
            parent[i]=sc.nextInt();
        }
        int[] res=new int[n+1];
        int max=Integer.MIN_VALUE;  //最小备份
        for (int i = 1; i < parent.length; i++) {
            res[i] = dfs(parent, i);
            max=Math.max(max,res[i]);
        }
        StringBuilder sb=new StringBuilder();
        for (int i = 1; i < res.length; i++) {
            if (max==res[i]){
                sb.append(i).append(" ");
            }
        }
        System.out.println(max);
        System.out.print(sb.substring(0,sb.length()-1));
    }
    static int[] dp=new int[100000+1];
    static int max=Integer.MIN_VALUE;
    public static int dfs(int[] parent,int i){
        if (dp[i]!=0){
            return dp[i];
        }
        if (parent[i]==-1){
            return 1;
        }
        dp[i]= dfs(parent, parent[i]) + 1;
        return dp[i];
    }
    static class Reader {
        private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        private StringTokenizer tokenizer = new StringTokenizer("");

        private String innerNextLine() {
            try {
                return reader.readLine();
            } catch (IOException ex) {
                return null;
            }
        }

        public boolean hasNext() {
            while (!tokenizer.hasMoreTokens()) {    //内存中没有
                String nextLine = innerNextLine();
                if (nextLine == null) {     //且没有下一行
                    return false;
                }
                tokenizer = new StringTokenizer(nextLine);  //读入一行
            }
            return true;
        }

        public String nextLine() {
            tokenizer = new StringTokenizer("");    //清空内存中的字符
            return innerNextLine();
        }

        public String next() {
            hasNext();
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }
    }
}
